(function () {
    //获取首页nav数据 并渲染到页面
    //<img src="${imgUrl}" alt=""></img>  
    fetch('http://chst.vip:1234/api/getindexmenu')
        .then(body => body.json())
        .then(res => {
            let result = res.result;
            // console.log(result);
            let navStr = '';
            result.map(items => {
                //console.log(item)
                let regExp = /^<[^<]+\s+src="([^''""]*)"/
                let mate = regExp.exec(items.img)
                navStr += `
            <li date-index="${items.indexmenuId}">
                <a href="${items.titlehref}">
                <img src="../${mate[1]}" id=${items.titlehref}></a>
                    <h4>${items.name}</h4>
            </li>
            `
            });
            $('.navlis').html($(navStr));
            //点击更多  展开第三行
            let isShow = true;
            $('.navlis > li').eq(7).on('click', function () {
                if (isShow) {
                    $(this).parent().stop().animate({ height: '2.55rem' }, 500);
                    isShow = false;
                } else {
                    $(this).parent().stop().animate({ height: '1.68rem' }, 500);
                    isShow = true;
                }
            })
        });
    //获取折扣列表数据  并渲染
    // <img src=${mate[0]} productid=${items.productId}>
    // <img src=../${mate[0]} alt=""}></img>
    // <h3>${items.productName}</h3>
    fetch('http://chst.vip:1234/api/getmoneyctrl').then(body => body.json()).then(res => {
        let result = res.result;
        console.log(result);
        let discStr = '';
        result.map(items => {
            console.log(items)
            let regExp = /(?<=imgyrl=)[^'"]*/;
            let mate = items.productImg2.match(regExp);
            discStr += `
            <li date-productId="${items.productId}">
                   <a href="#">
                        <div class="imgico">
                        ${items.imgurl}
                         </div>
                        <div class="info">
                        <h3>${items.productName}</h3>
                            <span class="price">¥ ${items.productPinkage}</span>
                            <div class="desc">
                                <span class="times">${items.productFrom} | ${items.productTime}</span>
                                <div class="review">
                                    <i></i>
                                    <span>${items.productComCount}</span>
                                </div>
                            </div>
                        </div>
                    </a>
                </li>
            `
        });
        $('.discBody > ul').html($(discStr));
    });
    $('.discBody').on('click', 'li', function () {
        console.log(0)

        location.href = '../html/indexproduct.html?productid=' + $(this).attr('date-productId')
    })
})()